//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.4/xslt/JavaClass.xsl

package com.novix.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.automatedlogic.domino.sso.DominoUserProfile;
import com.novix.portal.framework.exceptions.CaptiveNotFoundException;
import com.novix.portal.framework.exceptions.TokenMissingException;
import com.novix.portal.framework.exceptions.UserMissingException;
import com.novix.portal.framework.util.IConstants;
import com.novix.portal.framework.util.UserContainer;

/**
 * MyEclipse Struts Creation date: 05-21-2005
 * 
 * XDoclet definition:
 * 
 * @struts:action
 * @struts:action-forward name="success" path="/form/welcomeUser.jsp"
 * @struts:action-forward name="failure" path="/jsp/opening-page.jsp"
 */
public class GoToSplashPageAction extends PortalBaseAction implements IConstants {
    /**
     * Logger for this class
     */
    private static final Logger logger = Logger.getLogger(GoToSplashPageAction.class);

    // --------------------------------------------------------- Instance
    // Variables

    // --------------------------------------------------------- Methods

    /**
     * Method execute
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        DominoUserProfile up = (DominoUserProfile) request.getSession().getAttribute(IConstants.DOMINO_USER_PROFILE);
        UserContainer uc = (UserContainer) request.getSession().getAttribute(IConstants.USER_CONTAINER);

        //this could be changed to check that the user has the authority to
        // view info for this captive
        //by looking up the captive in the user's person doc as below
        if (StringUtils.isEmpty(uc.getUser().getCaptive())) {
            String captiveName = checkDominoUserProfile(request, getServlet().getServletContext().getInitParameter(IConstants.DOMINO_DIIOP_SERVER_NAME));
            if (StringUtils.isEmpty(captiveName))
                throw new CaptiveNotFoundException();
            else {
                uc.getUser().setCaptive(captiveName);
                uc.setCaptiveName(captiveName);
            }
        }
        try {
            setUserToken(request, uc);
        } catch (TokenMissingException e) {
            return mapping.findForward(IConstants.HOME);
        } catch (UserMissingException e) {
            return mapping.findForward(IConstants.LOGIN);
        }
        return mapping.findForward(IConstants.SUCCESS);
    }

}